import unittest
from bodhi.utils.tagbuilder import *

class TagBuilderTestCase(unittest.TestCase):
    
    def setUp(self):
        self.tb = TagBuilder('div')

    def test_one_class(self):
        self.tb.add_class('ab')
        self.assertEqual(self.tb.generate(), '<div class="ab"></div>')

    def test_multiple_classes(self):
        self.tb.add_class('ab')
        self.tb.add_class('cd')
        self.assertEqual(self.tb.generate(), '<div class="ab cd"></div>')

    def test_multiple_attr(self):
        self.tb.add_attr('id', 'id_form')
        self.tb.add_class('ab')
        self.tb.add_class('cd')
        self.assertEqual(self.tb.generate(), '<div id="id_form" class="ab cd"></div>')

    def test_self_closing(self):
        self.tb.add_attr('id', 'id_form')
        self.tb.add_class('ab')
        self.assertEqual(self.tb.generate('self_closing'), '<div id="id_form" class="ab" />')

    def test_start(self):
        self.tb.add_attr('id', 'id_form')
        self.tb.add_class('ab')
        self.assertEqual(self.tb.generate('start'), '<div id="id_form" class="ab">')

    def test_end(self):
        self.tb.add_attr('id', 'id_form')
        self.tb.add_class('ab')
        self.assertEqual(self.tb.generate('end'), '</div>')

    def test_wrong_mode(self):
        with self.assertRaises(ValueError):
            self.tb.generate('wrong_mode')

    def test_escape(self):
        self.tb.add_attr('any', '&"')
        self.assertEqual(self.tb.generate('start'), '<div any="&amp;&quot;">')

    def test_not_escape(self):
        self.tb.add_attr('any', '&"')
        self.assertEqual(self.tb.generate('start', False), '<div any="&"">')
